var ws, spage, arrList;
if(window.plus){
	ready();
}else{
	document.addEventListener('plusready' , ready, false);
}
function ready(){
	ws = plus.webview.currentWebview();
	spage = ws.spage;
	showWating();
	//读取病理症状
	$.ajax({
		type :"get",
		url :apiRoot+"/home/medicinal/symptom",
		dataType :'json',
		complete :function(){
			plus.nativeUI.closeWaiting();
		},
		success :function(data){
			arrList = data;
			if(data.length > 0){
				var list = '';
				$.each(data, function(k, v) {
					list = '<a class="mui-control-item '+(k==0?'mui-active':'')+'" href="#item'+k+1+'mobile" tid="'+v.tid+'">'+v.classname+'</a>';
					$('#sliderSegmentedControl .mui-scroll').append(list);
					if(k == 0){
						symptom_list(v.tid);
					}
				});
				//点击切换
				$('#sliderSegmentedControl a').on('tap',function(){
					var tid = $(this).attr('tid');
					symptom_list(tid);
				})
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
		}
	});
	//点击确定
	$('header span').on('tap', function(){
		var str = '';
		$("input[type='checkbox']:checked").each(function(){
			str += $(this).siblings('label').text()+" ";
		})
		if(str == ''){
			toast('请选择症状');
			return;
		}
		console.log(str);
		mui.fire(plus.webview.getWebviewById(spage), 'bingz', {str:str});
		ws.close();
	})
}
function symptom_list(tid){
	$.each(arrList, function(k1, v1) {
		if(v1.tid == tid){
			var cont = '';
			$.each(v1.level, function(k, v) {
		    	cont += '<li class="mui-table-view-cell mui-collapse">'+
					'<a class="mui-navigate-right" href="#">'+v.classname+'</a>'+
					'<ul class="mui-table-view mui-table-view-chevron">';
				if(v.symptom){
					$.each(v.symptom.symptom, function(k2, v2) {
						cont += '<li class="mui-table-view-cell toppp">'+
							'<div class="mui-input-row mui-checkbox mui-left">'+
								'<label>'+v2+'</label>'+
								'<input name="checkbox" value="Item 1" type="checkbox"/>'+
							'</div>'+
						'</li>';
					});
				}
			cont += '</ul>'+
				'</li>';
			});
			$('#scroll1 ul').html(cont);
		}
	});
}
